import 'package:get/get.dart';
import 'package:oramemo/core/repositories/default_api.dart';
import 'package:oramemo/entity/msg_entity.dart';
import 'package:oramemo/pages/first/msg/model.dart';

import 'msg_detail_state.dart';

class MsgDetailLogic extends GetxController {
  final state = MsgDetailState();
  final MessageModel data = Get.arguments;

  @override
  void onInit() {
    super.onInit();
    _initData();
  }

  void _initData() {
    if (Get.arguments != null) {
      state.title = data.title ?? '';
      state.content = data.content ?? '';
    }
    update();
  }

  Future<void> load() async {
    state.isLoading = true;
    update();
    
    try {
      // 模拟加载过程
      await Future.delayed(const Duration(seconds: 2));
      // MsgEntity? res = await DefaultApi().oraUserMessage1Get<MsgEntity>(id: 'id');
    } catch (e) {
      // 处理错误
    } finally {
      state.isLoading = false;
      update();
    }
  }

  void cancelLoading() {
    state.isLoading = false;
    update();
  }
}
